package cn.hengzhu.main_manager.utils.task;



import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;

import cn.hengzhu.main_manager.repository.vo.CaseInitVO;
import cn.hengzhu.main_manager.service.ManageCaseBoxService;


/**
 * mq消费者
 * @author 刘成
 * @since 2018年9月5日 关闭箱门后结费的处理逻辑
 */

@Component(value="closeBox")
public class CloseBox implements MessageListener {
	
	
	@Autowired
	private ManageCaseBoxService manageCaseBoxService;

	@Override
	public void onMessage(Message message) {
		try {
			byte[] body = message.getBody();
			String msg = new String(body, "utf-8");
			//1.消息的读取
			ObjectMapper mapper = new ObjectMapper();
			CaseInitVO readValue = mapper.readValue(msg, CaseInitVO.class);
			//2.处理消息
			if(readValue !=null){
				manageCaseBoxService.closeBoxAndPay(readValue);
			}
			
		} catch (Exception e) {

		}
	}
	
	
	
	

}
